<?php

     session_start();
     include('common.php');

    if (session_is_registered(MySBB_Admin_username) and $member_permission == 1)
    {

// **  **
             if ($_GET['main'] == 1)
             {
                 $Smarty->display('options.tpl');
             }

// **  **
         if ($groupper_row['admincp_option'] != 1)
         {
             $SF->error('المعذره .. هذه الميزه غير متاحه لك !');
         }

// **  **

         if ($_GET['general'] == 1)
         {
             if ($_GET['index'] == 1)
             {
                 $SF->Make_cplink_path('الاعدادات العامه');

                 $group_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "group");

                 $groups_rows = array();
                 while ($group_row = $DB->sql_fetch_array($group_query))
                 {
                     $groups_rows[] = $group_row;
                     $Smarty->assign('group_rows',$groups_rows);
                 }

                 $agroup_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "group");

                 $agroups_rows = array();
                 while ($agroup_row = $DB->sql_fetch_array($agroup_query))
                 {
                     $agroups_rows[] = $agroup_row;
                     $Smarty->assign('agroup_rows',$agroups_rows);
                 }

                 $Smarty->assign_by_ref('def_row',$def_row);
                 $Smarty->assign_by_ref('adef_row',$adef_row);

                 $getex_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "contactus_extensions ORDER BY id DESC");

                 $getex_rows = array();
                 while ($getex_row = $DB->sql_fetch_array($getex_query))
                 {
                     $getex_rows[] = $getex_row;
                     $Smarty->assign('getex_rows',$getex_rows);
                 }

                 $Smarty->display('options_main.tpl');
             }

             if ($_GET['start'] == 1)
             {
                 $meta = ((!get_magic_quotes_gpc()) ? addslashes($_POST['meta']) : $_POST['meta']);

                 $active       = $_POST['active'];
                 $forvisitors  = $_POST['forvisitors'];
                 $method       = intval($_POST['method']);
                 $email        = $_POST['email'];
                 $titles       = $_POST['titles'];
                 $link         = $_POST['link'];
                 $perpage      = intval($_POST['perpage']);
                 $attachactive = intval($_POST['attachactive']);
                 $sig          = $_POST['sig'];

                 $update       = $DB->sql_query("UPDATE " . $db_prefix . "info SET
                                 title='" . $_POST['T1'] . "',
                                 icon_path='" . $_POST['T2'] . "',
                                 send_email='" . $_POST['T3'] . "',
                                 admin_email='" . $_POST['T8'] . "',
                                 show_onlineguest='" . $_POST['D1'] . "',
                                 show_subject_all='" . $_POST['D2'] . "',
                                 perpage='" . $_POST['T5'] . "',
                                 subject_perpage='" . $_POST['T6'] . "',
                                 avatar_perpage='" . $_POST['T7'] . "',
                                 Sat='" . $_POST['Sat'] . "',
                                 Sun='" . $_POST['Sun'] . "',
                                 Mon='" . $_POST['Mon'] . "',
                                 Tue='" . $_POST['Tus'] . "',
                                 Wed='" . $_POST['Wed'] . "',
                                 Thu='" . $_POST['Thu'] . "',
                                 Fri='" . $_POST['Fri'] . "',
	               auto_center_sub='" . $_POST['autocenter'] . "',
	                member_latest_topics_activate = '" . $_POST['mysub'] . "',
	                member_latest_topics = '" . $_POST['mysubn'] . "',
                                 fastreply_allow='" . $_POST['fast'] . "',
                                 separate_allow='" .$_POST['sep'] . "',
                                 download_path='" . $_POST['download_path'] . "',
                                 def_group='" . $_POST['def_group'] . "',
                                 board_close='" . $_POST['close'] . "',
                                 board_msg='" . $_POST['close_msg'] . "',
                                 adef_group='" . $_POST['adef_group'] . "',
                                 use_list='" . $_POST['use_list'] . "',
                                 reg_o = '" . $_POST['reg_o'] . "',
                                 time_out = '" . $_POST['time_out'] . "',
                                 page_max='" . $_POST['page_max'] . "',
                                 reg_less_num='" . $_POST['reg_less_num'] . "',
                                 reg_max_num='" . $_POST['reg_max_num'] . "',
                                 reg_pass_max_num='" . $_POST['reg_pass_max_num'] . "',
                                 reg_pass_min_num='" . $_POST['reg_pass_min_num'] . "',
                                 post_text_max='" . $_POST['post_text_max'] . "',
                                 post_text_min='" . $_POST['post_text_min'] . "',
                                 post_title_max='" . $_POST['post_title_max'] . "',
                                 post_title_min='" . $_POST['post_title_min'] . "',
                                 samesubject_show='" . $_POST['samesubject_show'] . "',
                                 toolbox_show='" . $_POST['toolbox_show'] . "',
                                 smiles_show='" . $_POST['smiles_show'] . "',
                                 icons_show='" . $_POST['icons_show'] . "',
                                 title_quote='" . $_POST['title_quote'] . "',
                                 meta='$meta',
                                 time_out = '" . $_POST['time_out'] . "',
                                 floodctrl='".intval($_POST['floodctrl'])."',
                                 timestamp = '" . addslashes( $_POST['timestamp'] ) . "',
                                 timesystem = '" . addslashes( $_POST['timesystem'] ) . "',
                                 reg_close='" . $_POST['register_close'] . "',
                                 confirm_on_change_mail='" . $_POST['confirm_on_change_mail'] . "',
                                 confirm_on_change_pass='" . $_POST['confirm_on_change_pass'] . "',
                                 allow_avatar='" . $_POST['allow_avatar'] . "',
                                 allow_apsent='" . $_POST['allow_apsent'] . "',
                                 upload_avatar='" . $_POST['upload_avatar'] . "',
                                 contactus_active='$active',
                                 contactus_forvisitors='$forvisitors',
                                 contactus_method='$method',
                                 contactus_email='$email',
                                 contactus_titles='$titles',
                                 contactus_link='$link',
                                 contactus_perpage='$perpage',
                                 contactus_attachactive='$attachactive',
                                 contactus_sig='$sig',
                                 resize_imagesAllow = '" . $_POST['resize_imagesAllow'] . "',
                                 max_avatar_width = '" . $_POST['max_avatar_width'] . "',
                                 max_avatar_height = '" . $_POST['max_avatar_height'] . "',
                                 default_imagesW = '" . $_POST['default_imagesW'] . "',
                                 default_imagesH = '" . $_POST['default_imagesH'] . "',
                                 online_now_section='" . intval($_POST['online_now_section']) . "',
                                 online_now_subject='" . intval($_POST['online_now_subject']) . "',
                                 banned_email = '" . addslashes( $_POST['banned_email'] ) . "',
                                 banned_pemail = '" . addslashes( $_POST['banned_pemail'] ) . "',
                                 banned_name = '" . addslashes( $_POST['banned_name'] ) . "'
                                 ");


                 if ($update)
                 {
                     $SF->msg('تم التحديث بنجاح !');
                     $SF->go_to('option.php?general=1&index=1',2);
                 }
             }
         }

// **  **

         if ($_GET['msg'] == 1)
         {
             if ($_GET['index'] == 1)
             {
                 $SF->Make_cplink_path('التحكم بالرسائل');

                 $msg1_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "emailmsgs WHERE id='1'");
                 $msg2_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "emailmsgs WHERE id='2'");
                 $msg3_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "emailmsgs WHERE id='3'");
                 $msg5_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "emailmsgs WHERE id='5'");
                 $msg6_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "emailmsgs WHERE id='6'");

                 $msg1_row   = $DB->sql_fetch_array($msg1_query);
                 $msg2_row   = $DB->sql_fetch_array($msg2_query);
                 $msg3_row   = $DB->sql_fetch_array($msg3_query);
                 $msg5_row   = $DB->sql_fetch_array($msg5_query);
                 $msg6_row   = $DB->sql_fetch_array($msg6_query);

                 $Smarty->assign_by_ref('msg1_row',$msg1_row);
                 $Smarty->assign_by_ref('msg2_row',$msg2_row);
                 $Smarty->assign_by_ref('msg3_row',$msg3_row);
                 $Smarty->assign_by_ref('msg5_row',$msg5_row);
                 $Smarty->assign_by_ref('msg6_row',$msg6_row);

                 $Smarty->display('msg_main.tpl');
             }

             if ($_GET['start'] == 1)
             {
                 $update1 = $DB->sql_query("UPDATE " . $db_prefix . "emailmsgs SET title='" . $_POST['T1'] . "',text='" . $_POST['S1'] . "' WHERE id='1'");
                 $update2 = $DB->sql_query("UPDATE " . $db_prefix . "emailmsgs SET title='" . $_POST['T2'] . "',text='" . $_POST['S2'] . "' WHERE id='2'");
                 $update3 = $DB->sql_query("UPDATE " . $db_prefix . "emailmsgs SET title='" . $_POST['T3'] . "',text='" . $_POST['S3'] . "' WHERE id='3'");
                 $update5 = $DB->sql_query("UPDATE " . $db_prefix . "emailmsgs SET title='" . $_POST['T5'] . "',text='" . $_POST['S5'] . "' WHERE id='5'");
                 $update6 = $DB->sql_query("UPDATE " . $db_prefix . "emailmsgs SET title='" . $_POST['T6'] . "',text='" . $_POST['S6'] . "' WHERE id='6'");

                 $SF->msg('تم التحديث بنجاح !');
                 $SF->go_to('option.php?msg=1&index=1',2);
             }
         }

// **  **

    }

?>